global data_folder_final "W:\intimate\data"
global log_folder "W:\intimate\dofiles\logs"
global result_folder "W:\intimate\results_revision"

use "W:\intimate\data\match_victim_data_clean_new", clear

gen sample_cat="dv"
append using "W:\intimate\data\match_MFvictim_data_clean_new"
replace sample_cat="mf" if sample_cat==""

append using "W:\intimate\data\match_MMvictim_data_clean_new"
replace sample_cat="mm" if sample_cat==""


// pull the men's crime history 
rename sphnro0 sphnro
// all crimes 
merge m:1 sphnro year_event using "W:\intimate\data\cumul_crime_all", keepusing(cum_crimes) keep (1 3) nogen 
rename cum_crimes cum_crimes_all
replace cum_crimes_all=0 if cum_crimes_all==. 

// all violent crimes 
merge m:1 sphnro year_event using "W:\intimate\data\cumul_crime_violent", keepusing(cum_crimes) keep (1 3) nogen 
rename cum_crimes cum_crimes_violent 
replace cum_crimes_violent=0 if cum_crimes_violent==. 

// all mf crimes 
merge m:1 sphnro year_event using "W:\intimate\data\cumul_crime_violent_mf", keepusing(cum_crimes) keep (1 3) nogen 
rename cum_crimes cum_crimes_violent_mf
replace cum_crimes_violent_mf=0 if cum_crimes_violent_mf==. 


// crime types 
merge m:1 sphnro year_event using "W:\intimate\data\cumul_crime_violent_types_mf", keepusing(cum_assault cum_petty_assault cum_menace) keep (1 3) nogen 
replace cum_assault=0 if cum_assault==. 
replace cum_petty_assault=0 if cum_petty_assault==. 
replace cum_menace=0 if cum_menace==. 

eststo dv: estpost sum cum_crimes_all cum_crimes_violent cum_crimes_violent_mf cum_assault cum_petty_assault cum_menace if sample_cat=="dv"
eststo mf: estpost sum  cum_crimes_all cum_crimes_violent cum_crimes_violent_mf cum_assault cum_petty_assault cum_menace if sample_cat=="mf"
eststo mm: estpost sum  cum_crimes_all cum_crimes_violent cum_crimes_violent_mf cum_assault cum_petty_assault cum_menace if sample_cat=="mm"


esttab dv mf mm using "$result_folder\AppendixTable_male_dv_mf_mm_crimes.tex", replace cell("mean (pattern (1 1 1) fmt(2))") modelwidth (10) mtitle ("Male Suspects in DV couple" "Male Suspects in MF crimes" "Male Suspects in MM crimes") nonumber  coeflabel (cum_crimes_all "No. of prior crimes" cum_crimes_violent "No. of prior violent crimes" cum_crimes_violent_mf "No. of prior violent crimes against women" cum_assault "No. of assaults against women" cum_petty_assault "No. of petty assaults against women" cum_menace "No. of menace against women") title (Crime history and types) nonotes addn (Male suspects in different relationships)

